<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>VUE3</title>
  </head>
  <body>
    <div id="app"></div>

    <template id="tpl">
      <div>{{ fullName }}</div>
      <div>
        <input v-model="fullName" />
        <!-- <button @click="fullName = 'Li Si'">改变</button> -->
      </div>
    </template>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
      Vue.createApp({
        template: "#tpl",
        data() {
          return {
            firstName: "Zhang",
            lastName: "San",
          };
        },
        computed: {
          fullName: {
            get() {
              return [this.firstName, this.lastName].join(" ");
            },
            set(newValue) {
              console.log(newValue);
              const [firstName, lastName] = newValue.trim().split(" ");
              this.firstName = firstName || "";
              this.lastName = lastName || "";
            },
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
